#pragma once

#include "Dictionary.h"

class AdaptationData
{
private :
	std::string filename;
    std::fstream fileHandler;
    std::vector<std::string> fieldNames;
    std::vector<std::map<std::string, std::string> > segments;
    std::list<std::string> buffer;

    std::fstream openFile();
    void setFieldNames();
	bool isComplete(std::map<std::string, std::string> data);
    std::multimap<std::string, std::string, nosort<std::string> > createItem_(std::string);
    std::vector<std::multimap<std::string, std::string, nosort<std::string> > > searchAll_();

public:
	AdaptationData(std::string fileName);
	std::vector<std::multimap<std::string, std::string, nosort<std::string> > > search(std::multimap<std::string, std::string> criteria);
	bool isValidFieldName(std::string fieldName);
	bool isValidFieldName(std::map<std::string, std::string> data);
	bool insert(std::string row);
	bool update(std::map<std::string, std::string> oldData, std::map<std::string, std::string> newData);
	std::string createRow(std::map<std::string, std::string> data);
	std::string getValue(std::string row, std::string itemName);
	std::map<std::string, std::string> segmentToMap(std::string segment);
	void inputBuffer();
	void outputBuffer();
};
